package cn.javass.dp.templatemethod.example7;

public class Client {
    public static void main(String[] args) {
        LoginModel lm = new LoginModel();
        lm.setLoginId("admin");
        lm.setPwd("123456");
        LoginTemplate lt = new LoginTemplate();
        boolean flag = lt.login(lm, new LoginCallback() {
            @Override
            public LoginModel findLoginUser(String loginId) {
                LoginModel lm = new LoginModel();
                lm.setLoginId(loginId);
                lm.setPwd("222222");
                return lm;
            }

            @Override
            public String encryptPwd(String pwd, LoginTemplate template) {
                return template.encryptPwd(pwd);
            }

            @Override
            public boolean match(LoginModel lm, LoginModel dbLm, LoginTemplate template) {
                return template.match(lm,dbLm);
            }
        });

        System.out.println("普通登录人员flag = " + flag);

        boolean flag2 = lt.login(lm, new LoginCallback() {
            @Override
            public LoginModel findLoginUser(String loginId) {
                LoginModel lm = new LoginModel();
                lm.setLoginId(loginId);
                lm.setPwd("123456");
                return lm;
            }

            @Override
            public String encryptPwd(String pwd, LoginTemplate template) {
                System.out.println("加密过的pwd");
                return pwd;
            }

            @Override
            public boolean match(LoginModel lm, LoginModel dbLm, LoginTemplate template) {
                return template.match(lm,dbLm);
            }
        });
        System.out.println("内部人员登录flag2 = " + flag2);
    }


}
